/*
#
#  Copyright 2011 Matthew Jannace
#
#  This file is part of RoboCode BlackHoleAgent
#
#  RoboCode BlackHoleAgent is free software: you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as
#  published by the Free Software Foundation, either version 3 of the
#  License, or (at your option) any later version.
#
#  RoboCode BlackHoleAgent is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with RoboCode BlackHoleAgent. If not, see
#  <http://www.gnu.org/licenses/>.
#
 */
package com.jannaceltd.TeamBlackHoleBeer.Modules.Targeting.TargetingMethods;

import com.jannaceltd.TeamBlackHoleBeer.BlackHole_Abstract;
import com.jannaceltd.TeamBlackHoleBeer.Modules.Targeting.Targeting;
import com.jannaceltd.TeamBlackHoleBeer.Utilities.MathUtils;
import robocode.util.Utils;

/**
 * Class that Performs Head On Targeting
 * @author Matthew Jannace <mjannace@gmail.com>
 * @version 1.0
 *
 * Based on the HawkOnFire Robot created by the author Ruzu
 * Original HawkOnFire Source can be found at the Link Below
 * @link http://www.robocoderepository.com/BotFiles/1575/HawkOnFireOS.java
 */
public class HeadOnTargeting {

    private BlackHole_Abstract Agent = null;
    private Targeting gun = null;

    /**
     * Creates a new HeadOnTargeting object
     * @param Agent
     * @param gun
     */
    public HeadOnTargeting(BlackHole_Abstract Agent, Targeting gun) {
        this.Agent = Agent;
        this.gun = gun;
    }

    /**
     * Performs Head On Targeting
     */
    public void doHeadOnTargeting() {
        if (Agent.target.getPos() != null) {
            double distanceToTarget = Agent.getPos().distance(Agent.target.getPos());

            //**** gun ******************//
            // HeadOnTargeting there's nothing I can say about this
            if (Agent.getGunTurnRemaining() == 0 && Agent.getEnergy() > 1) {
                gun.dofire(Math.min(Math.min(Agent.getEnergy() / 6d, 1300d / distanceToTarget), Agent.target.getEnergy() / 3d));
            }
            Agent.setTurnGunRightRadians(Utils.normalRelativeAngle(MathUtils.calcAngle(Agent.target.getPos(), Agent.getPos()) - Agent.getGunHeadingRadians()));
        }
    }
}
